package com.hzjq.core.worker

import com.hzjq.core.BlastDelegate
import com.hzjq.core.ErrorCode
import com.hzjq.core.bean.CapEntity
import com.hzjq.core.bean.CapProgressEntity
import com.hzjq.core.callback.Callback
import com.hzjq.core.callback.OnScanCapCallback

class ShipCapScanWork : ScanShipCapWork {

    constructor(callback: Callback<MutableList<CapEntity>>?) : super(callback)

    override fun onDoWorkStart(vararg args: Any) {
        onProgressChanged(
            2 + progress * (48 / 100),
            if (pe == null || pe!!.total == 0) "正在检测雷管信息" else "已检测到${pe!!.total}发雷管"
        )
    }

    override fun onScanShipSuccess(progress: CapProgressEntity) {
        if (callback is OnScanCapCallback) {
            (callback as OnScanCapCallback).notifyVoltageElectricChanged(
                progress.mVoltage,
                progress.mElectric
            )
        }
        if (progress.stateCode == 0) {
            if (progress.total <= BlastDelegate.getDelegate().getMaxSupportCapCount()) {
                if (progress.progress < 100) {
                    retry(progress.progress)
                } else {
                    doNext(0,progress.total)
                }
            } else {
                callback?.onError(ErrorCode.getErrorResult(113))
            }
        } else {
            onScanError(progress)
        }
    }
}